<?php


namespace App\Modules\Admin\Services\System;


use App\Modules\Admin\Entities\System\DictDataModel;
use App\Modules\Admin\Entities\System\DictTypeModel;
use App\Modules\Admin\Services\BaseService;
use Illuminate\Support\Facades\DB;

class DictTypeService extends BaseService
{

    public function __construct(DictTypeModel $dictModel)
    {
        $this->model = $dictModel;
    }
    public function lists(array $params) : array
    {
        $params['where_callback'] = function ($query) use ($params) {
            $request = request();
            if (!empty($search = $request->input('search', ''))) {
                $query->where('site_name', 'LIKE', '%' . trim($search) . '%')
                    ->orWhere('site_address', 'LIKE', '%' . trim($search) . '%');
            }
            if (!empty($dict_type = $request->input('dictType', ''))) {
                $query->where('dict_type',$dict_type);
            }
            if (!empty($dict_type = $request->input('dictLabel', ''))) {
                $query->where('dict_label',$dict_type);
            }
            if (!empty($status = $request->input('status', ''))) {
                $query->where('is_check',$status);
            }
        };
        $lists = parent::lists($params);
        return $lists; // TODO: Change the autogenerated stub
    }

    public function create(array $params)
    {
        DB::beginTransaction();
        try{

            parent::create($params); // TODO: Change the autogenerated stub
            DB::commit();
            return true;
        }catch (Exception $e){
            DB::rollBack();
            return false;
        }
    }
}